{% extends "layouts/base.html" %}

{% block title %} 员工表 {% endblock %}

<!-- Specific CSS goes HERE -->
{% block stylesheets %}{% endblock stylesheets %}

{% block content %}

    <!-- [ Main Content ] start -->
    <section class = "pcoded-main-container">
        <div class = "pcoded-content">
            <!-- [ breadcrumb ] start -->
            <div class = "page-header">
                <div class = "page-block">
                    <div class = "row align-items-center">
                        <div class = "col-md-12">
                            <div class = "page-header-title">
                                <h5 class = "m-b-10">员工表 </h5>
                            </div>
                            <ul class = "breadcrumb">
                                <li class = "breadcrumb-item"><a href = "{% url 'index' %}"><i
                                        class = "feather icon-home"></i></a></li>
                                <li class = "breadcrumb-item"><a href = "#!">基础数据</a></li>
                                <li class = "breadcrumb-item"><a href = "#!">员工表</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
            <!-- [ breadcrumb ] end -->
            <!-- [ Main Content ] start -->
            <div class = "row">

                <!-- [ stiped-table ] start -->
                <div class = "col-xl-12">

                    <div class = "card">
                        <div class = "card-header">
                            <a href = "{% url 'add_employee' %}" class = "btn btn-primary"><i
                                    class = "feather mr-2 icon-plus"></i>添加
                            </a>
                            <a href = "{% url 'export_excel' %}" class = "btn btn-primary"><i
                                    class = "feather mr-2 icon-download-cloud"></i>导出
                            </a>
                        </div>
                        <div class = "card-body table-border-style">
                            <h6><code>只显示在职员工</code></h6>
                            <div class = "table-responsive">
                                <table class = "table table-striped table-bordered text-center">
                                    <thead class = "thead-light">
                                        <tr>
                                            <th>序号</th>
                                            <th>工号</th>
                                            <th>姓名</th>
                                            <th>性质</th>
                                            <th>状态</th>
                                            <th>工序</th>
                                            <th>操作</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        {% for e in employees %}
                                            <tr>
                                                <td>{{ forloop.counter|add:ten_pIndex }}</td>
                                                <td>{{ e.jobnumber }}</td>
                                                <td>{{ e.jobname }}</td>
                                                <td>
                                                    {% if e.properties == 1 %}
                                                        正式工
                                                    {% elif e.properties == 2 %}
                                                        临时工
                                                    {% elif e.properties == 3 %}
                                                        派遣工
                                                    {% elif e.properties == 4 %}
                                                        部门援助
                                                    {% endif %}
                                                </td>
                                                <td>
                                                    {% if e.status == 1 %}
                                                        在职
                                                    {% elif e.status == 2 %}
                                                        离职
                                                    {% endif %}
                                                </td>
                                                <td>{{ e.process }}</td>
                                                <td>
                                                    <a href = "{% url 'update_employee' e.id %}"
                                                       class = "btn btn-sm btn-info">
                                                        <i class = "feather mr-2 icon-edit-2"></i>修改
                                                    </a>
                                                    <button type = "button" class = "btn btn-sm btn-danger del"
                                                            data-toggle = "tooltip" title = "删除只是把员工转为离职"
                                                            onclick = "javascript:del_employee({{ e.id }});">
                                                        <i class = "feather mr-2 icon-trash-2"></i>删除
                                                    </button>
                                                </td>
                                            </tr>
                                        {% endfor %}
                                    </tbody>
                                </table>
                            </div>
                            <nav aria-label = "Page navigation example">
                                <ul class = "pagination justify-content-end">
                                    <li {% if pIndex == 1 %}class = "page-item disabled"{% endif %} class = "page-item">
                                        <a class = "page-link"
                                           href = "{% url 'employee' pIndex|add:-1 %}"
                                           tabindex = "-1">上一页</a>
                                    </li>
                                    {% for p in plist %}
                                        <li {% if p == pIndex %}class = "page-item active"{% endif %}
                                            class = "page-item">
                                            <a class = "page-link"
                                               href = "{% url 'employee' p %}">{{ p }}</a>
                                        </li>
                                    {% endfor %}
                                    <li {% if pIndex == maxpages %}class = "page-item disabled"{% endif %}
                                        class = "page-item">
                                        <a class = "page-link"
                                           href = "{% url 'employee' pIndex|add:1 %}">下一页</a>
                                    </li>
                                </ul>
                            </nav>
                        </div>
                    </div>
                </div>
                <!-- [ stiped-table ] end -->
                <script>
                    function del_employee(eId) {
                        var r = confirm("你确定要删除吗？")
                        if (r) {
                            $.ajaxSetup({   //获取到cookie中的csrf_token,将其添加到ajax的请求头中,防止出现错误（Forbidden."CSRF token missing or incorrect"）
                                data: {csrfmiddlewaretoken: '{{ csrf_token }}'}
                            })
                            $.ajax({
                                url: "{% url 'del_employee' %}",
                                type: "post",
                                data: {"id": eId},
                                success: function (arg) {
                                    //alert("此记录已经被删除成功.")
                                    //swal("删除成功", "此记录已经被删除成功.", "success");
                                    window.location.reload()
                                    //$trEle.remove() //在页面上删除已经被删除的那行表格
                                },
                            })
                        }
                    }
                </script>

            </div>
            <!-- [ Main Content ] end -->
        </div>
    </section>
    <!-- [ Main Content ] end -->

{% endblock content %}

<!-- Specific Page JS goes HERE  -->
{% block javascripts %}{% endblock javascripts %}
